﻿using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Crm;

namespace Konekcija.Core.Reporting.Mappings.Crm
{
    public class MerchantMap : ClassMap<Merchant>
    {
        public MerchantMap()
        {
            Schema("crm");
            Table("Merchants");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            Map(x => x.Name).Nullable();
            Map(x => x.ServiceId).Nullable();
            Map(x => x.DateCreated).Nullable();

            References(x => x.Product);

            HasManyToMany(x => x.Users)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Cascade.None()
                .ParentKeyColumn("MerchantId")
                .ChildKeyColumn("UserId")
                .Table("security.UsersToMerchants");

            HasMany(x => x.MerchantFaqs)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("MerchantId");

            HasMany(x => x.MerchantNotifications)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("MerchantId");

            HasMany(x => x.Feedbacks)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("MerchantId");

            HasMany(x => x.CommunicationChannels)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("MerchantId");

            HasMany(x => x.Notifications)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("MerchantId");
        }
    }

}
